var vm=new Vue({
    el:"#goodsOrder",
    data:{
        goodsOrder:{},//产品订单
        num:1,
        orderid:1,
        Payment:1
    },
    mounted(){
        this.getPageData();
        this.createNative();
        //this.selectId();
    },
    methods:{
        //刷新页面或者从别的页面进入，提取this.goodsOrder的值
        getPageData:function (){
            this.goodsOrder=JSON.parse(localStorage.getItem('goodsOrder'));
            if (this.goodsOrder==null){
                this.goodsOrder={};
            }
        },
        //保存购买商品的信息
        saveData:function (){
            this.goodsOrder.payment=this.goodsOrder.payment*this.num;//应付价
            this.goodsOrder.num=this.num;
            localStorage.setItem('goodsOrder',JSON.stringify(this.goodsOrder));
        },
        //提交订单
        insertGoodsOrder:function (){
            axios.post("/goodsOrder/insertGoodsOrder.do",this.goodsOrder).then(function (response){
                if (response.data.success){
                    alert(response.data.message);
                    //localStorage.clear();
                    //window.location.href='/产品目录_列表页.html';
                }else {
                    alert(response.data.message)
                }
            })
        },
        //支付二维码
        createNative:function (){
            let that=this;
            axios.get("/pay/createNative.do?orderid=1").then(function (response){
                //that.orderid=response.data.out_trade_no;//订单号
                that.Payment=(response.data.total_fee/100).toFixed(2);//订单金额
                var qr=new QRious({
                    element:document.getElementById("qrious"),
                    size:250,
                    value:"response.data.code_url",
                    level:"H"
                })
            })
        },
        //为未支付保存订单
        add:function (){
            this.saveData();
            this.insertGoodsOrder();
            localStorage.clear();
        },
        //查询订单id
        /*selectId:function (){
            let that=this;
            axios.get("/goodsOrder/selectId.do").then(function (response){
                that.orderid=response.data;
            })
        }*/
    }
})